package com.paul.girl.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

@Aspect
@Component
public class HttpAspect {
    @Autowired
    private HttpServletRequest request;
    private final static Logger logger = LoggerFactory.getLogger(HttpAspect.class);

    @Pointcut("execution(public * com.paul.girl.controller.GirlController.*(..))")
    public void cut() {

    }

    @Before("cut()")
    public void doBefore(JoinPoint joinPoint) {
        //url
        logger.info("url={}",request.getRequestURL());
        //method
        logger.info("method={}",request.getMethod());
        //ip
        logger.info("ip={}",request.getRemoteAddr());
        //类方法
        logger.info("class_method={}", joinPoint.getSignature().getDeclaringType());
        //参数
        logger.info("args={}",joinPoint.getArgs());

    }

    @After("cut()")
    public void after() {
        logger.info("方法执行完毕");
    }
@AfterReturning(value = "cut()",returning = "object")
    public void doAfterReturn(Object object){
       logger.info("response={}",object);
    }
}
